<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./BrowerWebSocketClient.js" ></script>
    <title>Document</title>
</head>
<body>

<form onsubmit="return false">
    <h3>WebSocket 聊天室：</h3>
    <textarea  id="responseTest" style="width: 500px;height: 300px;"></textarea>
    <br>
    <input type="text" name="message" style="width: 300px;" value="Welcome to">
    <input type="button" value="发送消息" onclick="send(this.form.message.value)">
    <input type="button" value="清空聊天记录" onclick="javascript:document.getElementById('responseTest').value=''">
</form>
</body>
</html>

<script>
    wsApp = new BrowerWebSocketClient("ws://localhost:15001/ws")
    var ta = document.getElementById('responseTest')
    wsApp.set("onmessage",(req,res)=>{
        ta.value = ta.value + '\n' + req.params
    })
    wsApp.set("onopen",(req,res)=>{
        ta.value = '连接开启!'
    })
    wsApp.set("onclose",(req,res)=>{
        ta.value = '连接关闭!'
    })
    function send(message){
        wsApp.send("AAAAA")
    }
</script>